#!/bin/sh

ARCH=arm64-v8a
CUR_DIR=$(cd "$(dirname "$0")" && pwd)
THIRDPARTY_DIR=${CUR_DIR}/../../../../../tpc_c_cplusplus/lycium/usr
echo "CUR_DIR: ${CUR_DIR}, ${THIRDPARTY_DIR}"

mkdir -p $ARCH-build
export PKG_CONFIG_LIBDIR=${THIRDPARTY_DIR}/openssl/arm64-v8a/lib/pkgconfig:${THIRDPARTY_DIR}/zlib_1_3_1/arm64-v8a/share/pkgconfig:${THIRDPARTY_DIR}/xz/arm64-v8a/lib/pkgconfig:${THIRDPARTY_DIR}/zstd_1_5_6/arm64-v8a/lib/pkgconfig:${THIRDPARTY_DIR}/nghttp3/arm64-v8a/lib/pkgconfig:${THIRDPARTY_DIR}/nghttp2/arm64-v8a/lib/pkgconfig:${THIRDPARTY_DIR}/libxml2/arm64-v8a/lib/pkgconfig
# export PKG_CONFIG_LIB=${THIRDPARTY_DIR}/zlib_1_3_1/arm64-v8a/lib

echo "$(pkg-config --list-all)"

${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" \
        -DCMAKE_TOOLCHAIN_FILE=${OHOS_SDK}/native/build/cmake/ohos.toolchain.cmake \
        -DCURL_DIR=${THIRDPARTY_DIR}/curl/${ARCH}/lib/cmake/CURL \
        -DOPENSSL_ROOT_DIR=${THIRDPARTY_DIR}/openssl/${ARCH} \
        -DOPENSSL_INCLUDE_DIR=${THIRDPARTY_DIR}/openssl/${ARCH}/include -DOPENSSL_CRYPTO_LIBRARY=${THIRDPARTY_DIR}/openssl/${ARCH}/lib/libcrypto.a \
        -DOPENSSL_SSL_LIBRARY=${THIRDPARTY_DIR}/openssl/${ARCH}/lib/libssl.a \
        -DOHOS_ARCH=$ARCH -B$ARCH-build -S ./ -L  #> `pwd`/$ARCH-build/build.log 2>&1
make -j4 -C $ARCH-build VERBOSE=1 #>> `pwd`/$ARCH-build/build.log 2>&1
 # -DCMAKE_FIND_DEBUG_MODE=TRUE \
